<template>
  <div class="upload-box" :class="{ active: store.state.app.showUploadList }">
    <div class="relative-box">
      <div class="header">
        <div class="title">
          上传列表
          <span> ({{ fileList.length }}) </span>
        </div>
        <div
          class="btn"
          @click="
            () => {
              emits('close')
            }
          "
        >
          <el-icon class="icon"><close-bold /></el-icon>
        </div>
      </div>
      <div class="content">
        <div v-if="fileList.length > 0" class="filelist-box">
          <div
            v-for="(item, index) in fileList"
            :key="index"
            class="progress-box"
          >
            <p class="title-pro">{{ item.name }}</p>
            <el-progress
              class="el-progress-box"
              :text-inside="true"
              :stroke-width="24"
              :percentage="parseInt(item.percentage)"
              :status="setColor(item)"
            />
          </div>
        </div>
        <el-empty v-else />
      </div>
    </div>
  </div>
</template>

<script setup name="uploadList">
const emits = defineEmits(['close'])
const store = useStore()

function setColor(item) {
  const hasResponse = item.hasOwnProperty('response')
  if (hasResponse) {
    if (item.response.code === 200) {
      return 'success'
    } else {
      return 'exception'
    }
  } else {
    return 'format'
  }
}

const _uploadList = computed(() => {
  return store.state.upload.uploadList
})
const fileList = computed(() => {
  let list = Object.values(_uploadList.value)
  return list.reverse()
})
</script>

<style lang="scss" scoped>
.active {
  display: block !important;
}
.upload-box {
  display: none;
}
.relative-box {
  position: relative;
  height: 400px;
  width: 500px;
}
.header {
  display: flex;
  height: 50px;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid #f3f3f3;
  padding: 0 10px;
  z-index: 10;
  background: #fff;
  .btn {
    width: 20px;
    .icon {
      cursor: pointer;
      padding: 5px;
    }
  }
}

.content {
  padding: 0px 10px 20px 10px;
  .filelist-box {
    height: 347px;
    overflow-y: auto;
  }
  .progress-box {
    position: relative;
    .title-pro {
      position: absolute;
      left: 10%;
      top: 2px;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      width: 350px;
      color: #000;
      z-index: 9;
    }
  }
  .el-progress-box {
    margin-top: 15px;
  }
}
.upload-box {
  z-index: 20;
  box-shadow: 0px 12px 32px 4px rgba(0, 0, 0, 0.04),
    0px 8px 20px rgba(0, 0, 0, 0.08);
  background: #fff;
  position: fixed;
  right: 0;
  bottom: 0;
}
</style>
